package com.jingdianjichi.subject.domain.handler;

import com.google.common.base.Preconditions;
import com.jingdianjichi.subject.common.enums.IsDeletedFlagEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoTypeEnum;
import com.jingdianjichi.subject.domain.convert.BriefSubjectConverter;
import com.jingdianjichi.subject.domain.convert.RadioSubjectConverter;
import com.jingdianjichi.subject.domain.entity.SubjectAnswerBO;
import com.jingdianjichi.subject.domain.entity.SubjectBriefBO;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBO;
import com.jingdianjichi.subject.domain.entity.SubjectOptionBO;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.entity.SubjectInfo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectRadio;
import com.jingdianjichi.subject.infra.basic.service.SubjectBriefService;
import com.jingdianjichi.subject.infra.basic.service.SubjectRadioService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.security.auth.Subject;
import java.util.LinkedList;
import java.util.List;

/**
 * ClassName :BriefTypeHandler
 * Package :com.jingdianjichi.subject.domain.handler
 * Desciption :
 *
 * @Author :
 * @Create : 18:28
 * @Version :1.0
 */


@Component
public class BriefTypeHandler implements  SubjectTypeHandler{

    @Resource
    private SubjectBriefService subjectBriefService;


    /**
     * 单选题目的插入
     * @param subjectInfoBO
     */
    @Override
    public void add(SubjectInfoBO subjectInfoBO) {

        Preconditions.checkNotNull(subjectInfoBO.getSubjectAnswer(),"答案不能为空");
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBO.getId().intValue());
        subjectBrief.setSubjectAnswer(subjectInfoBO.getSubjectAnswer());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        //对于这种偏差过大的类的转换是无法实现映射的
        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public SubjectOptionBO querySubjetInfo(Integer id) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(id);
        SubjectBrief result = subjectBriefService.queryByConditions(subjectBrief);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;
    }
}
